<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/MasterPage.Master"
    Inherits="System.Web.Mvc.ViewPage<IEnumerable<Animoso.Domain.Introduction>>" %>

<%@ Import Namespace="Animoso.Domain" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Index
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h4>Introducties</h4>
    <fieldset>
        <table id="intro">
        <thead>
            <tr>
                <th>
                    Jaar
                </th>
                <th>
                    Aantal
                </th>
            </tr>
        </thead>
        <tbody>
            <% foreach (Introduction introduction in Model.OrderByDescending(x => x.Year))
               { %>
            <tr>
                <td>
                    <%=introduction.Year %>
                </td>
                <td>
                    <%=introduction.Registrations.Count %>
                </td>
                <% if (introduction.Year == DateTime.Now.Year)
                   {
                       if (introduction.CanRegister)
                       {%>
                <td>
                    Sluit inschrijvingen
                </td>
                <% }
                       else %>
                <% { %>
                <td>
                    Open inschrijvingen
                </td>
                <% } %>
                <%} %>
                <td>Bekijk inschrijvingen</td>
            </tr>
            <% } %>
            </tbody>
        </table>
    </fieldset>
    <%if (!(bool)ViewData["hasIntroduction"])
      { %>
    <a href="#" id="openRegistration">Open inschrijvingen voor introductie
        <%=DateTime.Now.Year %></a>
    <% } %>
    
    <script type="text/javascript">
        $('#openRegistration').click(function() {
            $.ajax({ url: "ManageIntroduction/Open", context: document.body,
                success: function(val) {
                    $('<tr><td>' + val.Year + '</td><td>0</td></tr>').appendTo('#intro tbody');
                    $('#openRegistration').remove();
                }
            });
        });
    </script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadPlaceHolder" runat="server">
</asp:Content>
